package com.zc.webnews.ui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.zc.webnews.R;

public class ShowNewsActivity extends BaseTranslucentActivity {

    private WebView webView;
    private Toolbar toolbar;
    private ImageView back;
    private TextView title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_news);
        initView();
        initData();
    }

    private void initData() {
        title.setText(R.string.detail);
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        Log.e("url",url);
        WebSettings webSettings = webView.getSettings();
        //设置可自由缩放网页
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setJavaScriptEnabled(true);
        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                webView.loadUrl(url);
                return true;
            }
        });
    }

    private void initView() {
        toolbar = (Toolbar) findViewById(R.id.show_news_title);
        back = (ImageView) toolbar.findViewById(R.id.iv_back_titlebar);
        title = (TextView) toolbar.findViewById(R.id.tv_title_bar);
        webView = (WebView) findViewById(R.id.show_news_webView);
        setOrChangeTranslucentColor(toolbar,getResources().getColor(R.color.dip_red));
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
